<template>
  <div>
<van-list
  v-model="loading"
  :finished="finished"
  finished-text="没有更多了"
  @load="onLoad"
>
  <van-cell v-for="(item,index) in list" :key="index" :title="item.title" />
</van-list>
  </div>
</template>

<script>
import { getResult } from '@/api/search'
export default {
  name: 'SearchResult',
  props: {
    searchText: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1
    }
  },
  components: {},
  created () {},
  mounted () {},
  methods: {
    async onLoad () {
      // 1.发请求
      const res = await getResult({
        page: this.page,
        per_page: 10,
        q: this.searchText
      })
      // 2.追加数据
      this.list.push(...res.data.data.results)
      this.page++
      // 3.改变状态值
      this.loading = false
      // 4.判断是否结束
      if (res.data.data.results.length === 0) {
        this.finished = true
      }
    }
  }
}
</script>

<style lang="less" scoped>

</style>
